<template>
  <ex-dialog
    width="500px"
    class="ex-diolog"
    title="修改角色名称"
    :visible="visible"
    @closeDialog="handleClose"
  >	
		<el-form :model="ruleForm" status-icon :rules="rules" ref="ruleForm" label-width="140px" class="demo-ruleForm">
			<el-form-item label="角色名称" prop="roleName">
				<el-input type="text" v-model="ruleForm.roleName" autocomplete="off" placeholder="请输入角色名称"></el-input>
			</el-form-item>
			<!-- submitForm('ruleForm') -->
			<el-form-item>
				<el-button @click="handleClose('ruleForm')">取消</el-button> 
        <el-button type="primary" @click="submitForm('ruleForm')">确认</el-button>   
			</el-form-item>
		</el-form>
  </ex-dialog>
</template>
<script>
// components
import Loading from '@/components/Loading/index'
import { mapGetters } from 'vuex'
// api
import {
  editRoleName,
} from '@/api/setting'

export default {
  components: {
    Loading
  },
  props: {
    visible: Boolean,
    id: String,
    roleName: String,
  },
  data() {
    return {
      roleList: [],
      defaultProps: {
        children: 'children',
        label: 'label'
      },
			ruleForm: {
				roleName: '',
			},
			rules: {
          roleName: [
            { required: true,message: '请输入子账号名称',trigger: 'blur' }
          ],
        }
    }
  },
  computed: {
  
  },
  created() {
    console.log('this.roleName',this.roleName)
    this.ruleForm.roleName = this.roleName
  },
  methods: {
    //编辑名称
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        console.log('valid',valid)
        if (valid) {
          var data = {
              id: this.id,
              roleName: this.ruleForm.roleName
            }
            editRoleName(data).then(res => {
              this.handleSuccess("修改成功")
            }).finally(() => {
              this.loading = false
            })
         
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
    
		//取消
    handleClose(formName) {
      this.$emit('update:visible', false)
			// this.$refs[formName].resetFields();
    },
		//确认
		handleConfirm(){
			this.$emit('success', '你好')
		},
    handleSuccess(msg) {
      if (msg === '已拒绝') {
        var type = 'error'
      } else {
        var type = 'success'
      }
      this.$message({
        message: msg,
        type: type,
        duration: 1500,
        onClose: () => {
          this.handleClose()
          this.$emit('success')
        }
      })
    },
  }
}
</script>
<style lang="scss" scoped>
.ex-diolog {
  ::v-deep .ex--dialog--footer {
    border: none !important;
		padding: 0 !important;
  }
	::v-deep .ex--dialog--main {
    padding: 10px 20px !important;
  }
}

</style>
